/**
 * 简单API服务器
 */
var path = require('path');
var url = require('url');
var express = require('express');
var middlewares = require('./lib/middlewares');

var app = express();
app.set('view engine', 'ejs');
app.set('views', path.resolve(__dirname, 'views'));

app.use(middlewares.extendAPIOutput);
require('./routes')(app);
app.use(middlewares.apiErrorHandle);
// app.get('/example', middlewares.ensureLogin, authorize.checkAuthorizeParams, function(req, res, next){
//   res.locals.loginUserId = req.loginUserId;
//   res.locals.appInfo = req.appInfo;
//   res.render('authorize');
// });

var server = app.listen(3000, function(){
  var host = server.address().address;
  var port = server.address().port;

  console.log('Example app listening at http://%s:%s', host, port);
})